package com.park.controller;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.park.model.BillingInformation;
import com.park.model.InvoiceUser;
import com.park.service.BillingInformationService;
import com.park.service.Utility;

@RequestMapping("billingInformation")
@Controller
public class BillingInformationController {
	@Autowired
	private BillingInformationService billingInformationService;
	@RequestMapping(value="insert",method=RequestMethod.POST,produces={"application/json;charset=utf-8"})
	@ResponseBody
	public String insert(@RequestBody BillingInformation billingInformation){
		Map<String,Object> resultMap = new HashMap<String, Object>();
		BillingInformation billingInfo = billingInformationService.get(billingInformation.getUserId(),billingInformation.getGmfNsrsbh());
		System.out.println(billingInfo);
		if(billingInfo == null) {
			int count = billingInformationService.insert(billingInformation);
			resultMap.put("status", 1001);
			resultMap.put("message", "添加成功");
		}else {
			resultMap.put("status", 1001);
			resultMap.put("message", "该信息已添加");
		}
		return Utility.gson.toJson(resultMap);
	}
	
	@RequestMapping(value="update",method=RequestMethod.POST,produces={"application/json;charset=utf-8"})
	@ResponseBody
	public String update(@RequestBody BillingInformation billingInformation){
		Map<String,Object> resultMap = new HashMap<String, Object>();
		int count = billingInformationService.update(billingInformation);
			resultMap.put("status", 1001);
			resultMap.put("message", "修改成功");
		return Utility.gson.toJson(resultMap);
	}
}
